package com.jianyun.jyzs.model;

import android.util.Log;

import com.jianyun.jyzs.bean.UpdataPwdBean;
import com.jianyun.jyzs.http.Api;
import com.jianyun.jyzs.http.CustomCallback;
import com.jianyun.jyzs.http.RetrofitHelper;
import com.jianyun.jyzs.model.imdoel.IUpdataPwdModel;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by yangshijun on 2018/5/28.
 */

public class UpdataPwdModel implements IUpdataPwdModel {
    private static UpdataPwdModel model;

    private UpdataPwdModel(){}

    public static UpdataPwdModel getInstance(){
        if (model==null){
            model=new UpdataPwdModel();
        }
        return model;
    }
    @Override
    public void updataPwd(String enterpriseCode, String userId, String oldPwd, String newPwd,
                          final OnUpdataPwdListener onUpdataPwdListene) {
        Api api = RetrofitHelper.builderErpHttp().create(Api.class);
        api.upDataPwd("UpdatePassword",enterpriseCode,userId,oldPwd,newPwd,"jyzs","Android","1.0.2")
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new CustomCallback<UpdataPwdBean>() {
                    @Override
                    protected void onResponse(UpdataPwdBean response) {
                        if (response.isResult()){
                            onUpdataPwdListene.onSuccess();
                        }else {
                            onUpdataPwdListene.onException(response.getMessage());
                        }
                        Log.i("test","修改密码："+response.toString());
                    }

                    @Override
                    protected void onException(String msg) {
                        onUpdataPwdListene.onFailed();
                    }
                });
    }
}
